package org.davidliebman.android.flyer;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;

public class SplashScreen extends Activity {

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       this.setContentView(R.layout.splashscreen);
       final SplashTimer mTimer = new SplashTimer();
       mTimer.execute();
       
       View mButton ;//= new View(this);
       
       mButton = (View) this.findViewById(R.id.splashscreenfull);
       
       mButton.setOnClickListener(new OnClickListener() {

		@Override
		public void onClick(View arg0) {
			
			mTimer.cancel(true);
			launchGame();
		}
    	   
       });
       
//       mButton.setOnTouchListener(new OnTouchListener () {
//
//		@Override
//		public boolean onTouch(View arg0, MotionEvent arg1) {
//			// TODO Auto-generated method stub
//			//mTimer.cancel(true);
//			launchGame();
//			return true;
//		}
//    	   
//       });
	}
	
	@Override
	public void onPause(){
		super.onPause();
		finish();
	}
	
	public void launchGame() {
		Intent mIntent = new Intent(SplashScreen.this, Pager.class);
		//mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);
    	startActivity(mIntent);
    	finish();
	}
	
	private class SplashTimer extends AsyncTask<Integer, Void, String> {
        @Override
        protected void onPreExecute() {
               
        }
        
        @Override
        protected String doInBackground(Integer ... mSec) {
                String mReturn = new String("");
                try {
                        Thread.sleep(4500);
                }
                catch (Exception e) {
                        //Log.e("Splash","interrupted");
                }
                return mReturn;
        }
        
        @Override
        protected void onPostExecute(String mResult) {
               launchGame();
        	
        }
}

}
